﻿using KouDai.Phone.Engine;
using KouDai.Phone.Models;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;

namespace KouDai.Phone.Parsers
{
    public class CategoryParser : BaseParser
    {
        public override void ParseData(string json, BackData backData)
        {
            List<HotEntity> categoryList = backData.ResposeData as List<HotEntity>;
            JObject jobjet = JObject.Parse(json);
            JToken jtoken = jobjet.SelectToken("result");
            foreach (JToken jt in jtoken.Children())
            {
                //大分类
                HotEntity categoryEntity = new HotEntity();
                categoryEntity.CombineAppId = jt["combine_app_id"].ToString();
                categoryEntity.OriginalAppName = jt["original_app_name"].ToString();
                categoryEntity.ImageUrl = jt["imgurl"].ToString();
                categoryEntity.OpenType = jt["openType"].ToString();

                //处理子分类
                List<HotEntity> subCateories = new List<HotEntity>();
                JToken subToken = jt.SelectToken("subCateories");
                foreach (JToken subJt in subToken.Children())
                {
                    HotEntity subCategoryEntity = new HotEntity();
                    subCategoryEntity.CombineAppId = subJt["combine_app_id"].ToString();
                    subCategoryEntity.OriginalAppName = subJt["original_app_name"].ToString();
                    subCateories.Add(subCategoryEntity);
                }
                categoryEntity.SubCateories = subCateories;
                categoryList.Add(categoryEntity);
            }
        }
    }
}
